#include <iostream>
#include <cmath>
#include "conio.h"

using namespace std;

void menu(float (*matrix)[4]);
void ausgeben(float (*matrix)[4]);
void transformation(float (*matrix)[4], char eingabe);
void finished();

int main() {
    float (*matrix)[4] = 0; 
    matrix = new float[4][4];

	cout << "Matrix Werte eingeben: " << endl;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			cout << "Wert[" << j << "][" << i << "] > ";
			cin >> matrix[j][i];
		}
	}

	menu(matrix);

    delete [] matrix;
	return 0;
}

void menu(float (*matrix)[4]) {
	bool exit = false;

	while (!exit) {
		char eingabe;
		system("cls");

		cout << "Menu:" << endl;
		cout << "	(x) um X-Achse drehen" << endl;
		cout << "	(y) um Y-Achse drehen" << endl;
		cout << "	(z) um Z-Achse drehen" << endl;
		//cout << "	(a) Matrix ausgeben" << endl;
		cout << "	(e) Ende..." << endl << endl;
		cout << "Eingabe > ";

		cin >> eingabe;

		switch (eingabe) {
			case 'x'	:	transformation(matrix, eingabe); break;
			case 'y'	:	transformation(matrix, eingabe); break;
			case 'z'	:	transformation(matrix, eingabe); break;
			case 'e'	:	exit = true; break;
		}
	}
}

void ausgeben(float (*matrix)[4]) {
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			cout << "[" << j << "][" << i << "] > " << (int)matrix[j][i] << " ";
		}
		cout << endl;
	}
}

void transformation(float (*matrix)[4], char eingabe) {
	float (*help)[4] = 0; 
    help = new float[4][4];

	// Hilfsmatrix mit 0en fuellen
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			help[i][j] = 0;
		}
	}
	cout << "... hilfsmatrix mit 0en gefuellt" << endl;

	long float tetha, winkel;

	const double PI = 3.1415926535897932384626433832795;

	cout << "Winkel eingeben: ";
	cin >> winkel;

	tetha = winkel*PI/180;

	cout << "... winkel berechnet" << endl;

	float transX[4][4] = {								// Transformationsmatrix
						{1,	0,          0,           0},
						{0, cos(tetha), -sin(tetha), 0},
						{0, sin(tetha), cos(tetha),  0},
						{0, 0,          0,           1}
					 };

    float transY[4][4] = {
						(cos(winkel),  0, sin(winkel), 0),
						(0,            1, 0,           0),
						(-sin(winkel), 0, cos(winkel), 0),
						(0,            0, 0,           1)
    };

	float transZ[4][4] = {
						(cos(winkel), -sin(winkel), 0, 0), 
						(sin(winkel), cos(winkel),  0, 0),
						(0,           0,            1, 0),
						(0,           0,            0, 1)
    };

	switch (eingabe) {
		case	'x'	:	{

			for(int i = 0; i < 4; i++){
				for(int j = 0; j < 4; j++){
					for(int k = 0; k < 4; k++){
						help[i][j] += matrix[k][j] * transX[i][k];
					}
				}
			}
			cout << "... matrix berechnet" << endl;
			break;
						}

		case	'y'	:	{
			for(int i = 0; i < 4; i++){
				for(int j = 0; j < 4; j++){
					for(int k = 0; k < 4; k++){
						help[i][j] += matrix[k][j] * transY[i][k];
					}
				}
			}
			cout << "... matrix berechnet" << endl;
			break;
						}

		case	'z'	:	{
			for(int i = 0; i < 4; i++){
				for(int j = 0; j < 4; j++){
					for(int k = 0; k < 4; k++){
						help[i][j] += matrix[k][j] * transZ[i][k];
					}
				}
			}
			cout << "... matrix berechnet" << endl;
			break;
						}
	}
	ausgeben(help);
	finished();

}

void finished() {
	cout << "Press the ANY-key to continue...";
	while (!_kbhit());
}